package com.example.weakreference;

import android.content.Context;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

/**
 * Created by kkmike999 on 2019/06/21.
 */
public class MyRunnable implements Runnable {

    public Reference reference;

    public MyRunnable(Context context) {
        reference = new WeakReference<>(context);
    }

    @Override
    public void run() {
//        reference.clear();
        System.out.println("Thread run() " + reference.get());
        try {
            Thread.sleep(30000 * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("完成 " + reference.get());
    }

    //    protected void clear() {
    //        reference.clear();
    //        System.out.println("clear后，get()=" + reference.get());
    //        reference = null;
    //    }
}
